<template>
	<view class="main-content">
		<MHeader ref="header">
			修改密码
		</MHeader>
		<!-- 主要信息 -->
		<van-cell title="新密码">
			<input type="password" v-model="state.info.password" />
		</van-cell>
		<van-cell title="确认密码">
			<input type="password" v-model="state.info.password2" />
		</van-cell>
		<van-button type="primary" size="small" block @click='confirm'>确认</van-button>
	</view>
</template>

<script setup>
	import { getCurrentInstance } from 'vue'
	import { reactive } from 'vue'
	import { onReady, onLoad } from '@dcloudio/uni-app'
	import kdApis from '../../../api/modularApi/kdApi.js'
	import { msg } from '../../../utils/utils'
	let state = reactive({
		info: {}
	})

	const confirm = () => {
		if (!state.info.password) return msg('请输入新密码！')
		if (state.info.password !== state.info.password2) return msg('两次输入密码不一致！')
		const obj = {
			password: state.info.password,
			userId: uni.getStorageSync('userInfo').Id
		}
		kdApis.changePassword(obj).then(res => {
			msg('密码修改成功！请重新登录！')
			let account = uni.getStorageSync('account')
			if (account) {
				account.password = ''
			}
			uni.setStorageSync('account', account)
			setTimeout(() => {
				uni.redirectTo({
					url: '/views/login/Login'
				})
			}, 300)
		})
	}
</script>

<style lang="scss" scoped>
	::v-deep .van-button {
		height: 74rpx;
		width: 660rpx;
		margin: 100rpx auto;
	}
</style>